//
//  XJWalletFinanceDetailViewController.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/23.
//  Copyright © 2018年 Tzyang. All rights reserved.
//  @"资金明细"    

#import "XJWalletFinanceDetailViewController.h"

//view
#import "XJWalletFinanceCell.h"
// Model
#import "XJWalletFinanceModel.h"

@interface XJWalletFinanceDetailViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic, strong) UITableView *tableView;
@property(nonatomic, strong) NSMutableArray *dataArray;

@end

@implementation XJWalletFinanceDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupView];

    [self requestDataWithFinanceType:self.finance_type];
}


- (void)setupView {
    
    if ([self.finance_type isEqualToString:@"1"]) {
        
    }else if ([self.finance_type isEqualToString:@"4"]){
        self.navTitle = @"缴费明细";
    }else { //什么不传
        self.navTitle = @"资金明细";
    }

    self.tableView.frame = CGRectMake(0, 0, KWidth, KHeight - XJTopNavH);
    [self.view addSubview:self.tableView];
}

#pragma mark - 一 lazy
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:(UITableViewStylePlain)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        
        _tableView.rowHeight = 60;
        
        [_tableView registerClass:[XJWalletFinanceCell class] forCellReuseIdentifier:@"XJWalletFinanceCellId"];
        
        _tableView.tableFooterView = [UIView new];
    }
    return _tableView;
}

- (NSMutableArray *)dataArray {
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

#pragma mark - 三 UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    XJWalletFinanceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"XJWalletFinanceCellId"];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    XJWalletFinanceModel *model = self.dataArray[indexPath.row];
    
    cell.financeModel = model;
    
    return cell;
}


#pragma mark - 请求数据
- (void)requestDataWithFinanceType:(NSString *)finance_type {
    
    [XJHttpTool requestCustomAccountFinanceLsitWithFinceType:finance_type successH:^(id responseObjc) {
        NSString *code = [NSString stringWithFormat:@"%@",responseObjc[@"code"]];
        if ([code isEqualToString:@"0"]) {
            NSArray *finance_list = responseObjc[@"data"][@"finance_list"];
            for (NSDictionary *dic in finance_list) {
                XJWalletFinanceModel *model = [XJWalletFinanceModel mj_objectWithKeyValues:dic];
                
                [self.dataArray addObject:model];
            }
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.tableView reloadData];
        });
    } failH:^(NSError *error) {
        [JRToast showWithText:[error localizedDescription]];

    }];
}
@end
